/**
 * AdminEmployeeListDAO class.
 */
package pits.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import pits.dto.EmployeeDTO;

public class AdminEmployeeListDAO {

	public List<EmployeeDTO> getData() {
		// new pits.util.Logger().write("getEmployeeInfo start");

		List<EmployeeDTO> result = new ArrayList<EmployeeDTO>();
		EmployeeDTO dto = null;
		Connection conn = null;
		String query = null;
		ResultSet rs = null;
		PreparedStatement pStat = null;

		try {
			query = "SELECT * FROM employee WHERE isDeleted=0";
			conn = pits.util.Connection.getConnection();
			pStat = conn.prepareStatement(query);
			rs = pStat.executeQuery();
			while (rs.next()) {
				dto = new EmployeeDTO();
				dto.setEmpID(rs.getInt("EmpID"));
				dto.setName(rs.getString("Name"));
				dto.setBirthday(rs.getString("Birthday"));
				dto.setAddress(rs.getString("Address"));
				dto.setEmail(rs.getString("Email"));
				dto.setGender(rs.getByte("Gender"));
				dto.setPhone(rs.getString("Phone"));
				result.add(dto);
			}
		} catch (Exception sqlEx) {
			new pits.util.Logger().writeln("EmployeeDAO.getEmployeeInfo " + sqlEx);
		} finally {
			try {
				// rs.close();
				pStat.close();
				conn.close();
			} catch (SQLException sqlEx) {
				new pits.util.Logger().writeln("EmployeeDAO.getEmployeeInfo " + sqlEx);
			}
		}

		return result;
	}
}
